<template>
  <div >
    <!-- 阿里云视频播放器样式 -->
    <link rel="stylesheet"
          href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css" >
    <!-- 阿里云视频播放器脚本 -->
    <script charset="utf-8" type="text/javascript"
            src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js" />

    <!--播放器页面布局-->
    <div class="video_content"> <!--左侧播放器-->
        <div class="back_button">
            <!--视频上方返回链接-->
            <a :href="'/video/'+contentId">
            <i class="el-icon-back" style="font-size: 25px; color: white; position: absolute; left: 12px; top: 28px;"/>|
            <span>{{content.title}}</span>
            </a>
          </div>
        <!--播放器信息-->
        <div id="J_prismPlayer" class="prism-player" />
    </div>

    <!--右侧目录-->
    <div class="catalogue">
        <!--顶部作品信息-->
        <div class="videoPlay_right_top">
          <img :src="content.cover" >
          <span>
          <p class="dan">{{content.title}}</p>
          <span style="color:white">购买人数：</span>
            <i class="pinfen_num">{{content.buyCount}}</i>
         </span>
          <div class="clearfix"></div>
        </div>
        <div class="line"></div>
        <div class="m-chapterList" >
          <div v-for="(chapter,index) in chapterList" :key="chapter.id">
            <div class="chapter">
              <span class="f-fl ch">章节</span>
              <span class="f-fl f-thide chaptericon"><span>{{index+1}}</span></span>
              <span class="f-fl f-thide chaptername">{{chapter.title}}</span>
            </div>
            <div class="section"
                 :class="video.videoSourceId == vid?'video_active':''"
                 v-for="video in chapter.children" :key="video.id"
                 @click="videoClick(video.videoSourceId,video.isFree)">
              <span class="f-fl f-thide ks" style="color: rgb(153, 153, 153);">&nbsp;</span>
              <span class="f-fl ksw" style="background: rgb(245, 247, 250);">
                <span class="u-clicon ksicon ksicon-20" title="进行中"></span></span>
              <span class="f-fl ksname" style="color: rgb(153, 153, 153);">{{ video.title }}</span>
              <span class="f-fr ksinfo"><span class="f-fr ksinfoicon ksinfoicon-2" title="视频"></span>
                <span class="f-fr kstime">{{video.duration}}</span><span class="f-fr flag flag-10" ></span>
              </span>
            </div>
          </div>
        </div>
    </div>
  </div>
</template>
<script>
import vod from '@/api/vod'
import content from "@/api/content";
import "~/assets/css/video.css";
import banner from "@/api/banner";
export default {
  layout: 'video',//应用video布局
  //加载数据
  async asyncData(app) {
    /**传入了两个参数,使用_分隔 拆分参数*/
    var arr = app.params.vid.split("_");
    var vid = arr[0]
    var contentId = arr[1];
    let [request1Data, request2Data] = await Promise.all([
      //获取播放凭证
      vod.getPlayAuth(vid),
      //获取作品详情
      content.geContentDetailById(contentId,app)
    ])
    return {
      vid: vid,
      contentId:contentId,
      playAuth: request1Data.data.playAuth,
      content:request2Data.data.content,
      chapterList:request2Data.data.chapterVoList
    }
  },
  data(){
    return{
      contentId:'',
      aliPlayer:''
    }
  },

  methods:{
    videoClick(vid){
      this.vid = vid;
      vod.getPlayAuth(vid).then(response => {
        this.playAuth = response.data.playAuth;
        this.aliPlayer.replayByVidAndPlayAuth(vid,this.playAuth);
      })
    }
  },
  mounted() {
      //页面渲染之后
       this.aliPlayer = new Aliplayer({
            id: 'J_prismPlayer',
            vid: this.vid, // 视频id
            playauth: this.playAuth, // 播放凭证
            encryptType: '1', // 如果播放加密视频，则需设置encryptType=1，非加密视频无需设置此项
            width: '1500px',
            height: '815px',
            // 以下可选设置
            qualitySort: 'asc', // 清晰度排序
            mediaType: 'video', // 返回音频还是视频
            autoplay: false, // 自动播放
            isLive: false, // 直播
            rePlay: false, // 循环播放
            preload: true,
            controlBarVisibility: 'hover', // 控制条的显示方式：鼠标悬停
            useH5Prism: true, // 播放器类型：html5
        }, function(player) {
            console.log('播放器创建成功')
        })
       /*this.videoClick(this.vid);*/
  }
}
</script>
<style>

</style>
